#ifndef __U_I2C_H__
#define __U_I2C_H__

#include "gd32f10x.h"

//GPIOB					(*(struct	GPIO_TypeDef	*)(0x40010c00))
#define GPIOB_CRL		(*(volatile unsigned long *)(0x40010c00))
#define GPIOB_CRH		(*(volatile unsigned long *)(0x40010c04))
#define GPIOB_IDR		(*(volatile unsigned long *)(0x40010c08))
#define GPIOB_ODR		(*(volatile unsigned long *)(0x40010c0c))
#define GPIOB_BSRR		(*(volatile unsigned long *)(0x40010c10))
#define GPIOB_BRR		(*(volatile unsigned long *)(0x40010c14))
#define GPIOB_LCKR		(*(volatile unsigned long *)(0x40010c18))

#define RCU_APB2EN_		(*(volatile unsigned long *)(0x40021018))

//#define IIC_SDAH		GPIOB_BSRR=	0x0200
//#define IIC_SDAL		GPIOB_BRR=0x0200
//#define IIC_SDAX		(GPIOB_IDR&0x0200)
//#define IIC_SCLH		GPIOB_BSRR=	0x0100
//#define IIC_SCLL		GPIOB_BRR=	0x0100

#define	IIC_SCLL		(gpio_bit_reset(GPIOB,GPIO_PIN_8))
#define	IIC_SCLH		(gpio_bit_set(GPIOB,GPIO_PIN_8))

//#define	IO_I2C_SCL_LOW		(GPIO_OCTL(GPIOB) &=~GPIO_PIN_8)
//#define	IO_I2C_SCL_HIGH		(GPIO_OCTL(GPIOB) |=GPIO_PIN_8)

#define	IIC_SDAL		(gpio_bit_reset(GPIOB,GPIO_PIN_9))
#define	IIC_SDAH		(gpio_bit_set(GPIOB,GPIO_PIN_9))

//#define	IO_I2C_SDA_LOW		(GPIO_OCTL(GPIOB) &=~GPIO_PIN_9)
//#define	IO_I2C_SDA_HIGH		(GPIO_OCTL(GPIOB) |=GPIO_PIN_9)

#define IIC_SDAX		(gpio_input_bit_get(GPIOB, GPIO_PIN_9)== SET)


//#define IIC_InitIO	GPIOB_CRH = 0x00000077 
//#define IIC_InitIOD	GPIOB_ODR = 0x0300	
//#define IIC_InitPB	RCU_APB2EN_ = 0x0008

#define	SD5075_ADDR0	0x90
#define 	SD5075_ADDR1	0x9e
#define 	SD5075_ADDR2	0x92
#define 	AT24C_ADDR	0xA0

int16_t Get_Temperature(uint8_t ADDR);
void IIC_RD_AT24(uint8_t DEVICE,uint16_t ADDR,uint16_t num,uint8_t *p);
uint8_t  IIC_WD_AT24(uint8_t DEVICE,uint16_t ADDR,uint16_t num,uint8_t *p);
void IIC_Init(void);
	
#endif 
